<?php
namespace app\user\controller;
use think\Db;
use think\facade\Request;
class Xigu extends Common{
    protected $uid;
    public function initialize()
    {
        parent::initialize();
        $this->uid=session('user.id');
    }


    public function index(){
        if(request()->isPost()){
            $data = input('post.');
            $user = db('users');
            $oldEmail = $user->where('id',$this->uid)->value('email');
            if(Db::name('users')->where([['email','=',$data['email']],['id','neq',$this->uid]])->find()){
                return ['status'=>0,'msg'=>'该邮箱已被注册！'];
            }

            if($oldEmail != $data['email']){
                $data['email_validated'] = 0;
            }
            if (Db::name('users')->where('id',$this->uid)->update($data)!==false) {
                $result['msg'] = '编辑资料成功!';
                $result['status'] = 1;
            } else {
                $result['msg'] = '编辑资料失败!';
                $result['status'] = 0;
            }
            return $result;
        }else{
            $province = Db::name('Region')->where ('pid',1)->select ();
            $this->assign('province',$province);
            $city = Db::name('Region')->where ( 'pid',$this->userInfo['province'])->select ();
            $this->assign('city',$city);
            $district = Db::name('Region')->where ('pid',$this->userInfo['city'])->select ();
            $this->assign('district',$district);
            $this->assign('title','基本设置');
            return $this->fetch();
        }
    }
//设置
    public  function setting(){

        $user=getuser($this->uid);
        $this->assign('user', $user);
        $this->assign('title','设置');
        return $this->fetch();
    }
    //修改安全码
    public function update_pwd(){
        $user=getuser($this->uid);
        $this->assign('user', $user);
        $this->assign('title','修改密码');
        return $this->fetch();
    }
    public function update_pwd_do(){
        $user=getuser($this->uid);
        $data=input('post.');
        if(md5($data['oldsafepassword'])!=$user['paypwd']){
            $data=array('state'=>0001,'msg'=>'原密码不正确');
            echo json_encode($data) ;die();
        }else{
            $paypwd=md5($data['newsafepassword']);
            db('users')->where('id',$user['id'])->setField('paypwd',$paypwd);
            $data=array('state'=>0001,'msg'=>'修改成功');
            echo json_encode($data) ;die();
        }
    }
    //修改手机号
    public function update_tel(){
        $user=getuser($this->uid);
        $this->assign('user', $user);
        $this->assign('title','修改手机号');
        return $this->fetch();
    }
    //意见反馈
    public function tousu(){
        $user=getuser($this->uid);
        $this->assign('user', $user);
        $this->assign('title','意见反馈');
        return $this->fetch();
    }
    //意见反馈
    public function tousu_do(){
        $user=getuser($this->uid);
        $data=input('post.');
        $tousu=array(
            'content'=>$data['content'],
            'img_url'=>$data['buttons'],
            'mobile'=>$data['contact']
        );
        db('tousu')->insert($tousu);
        $data=array('state'=>0000,'msg'=>'提交成功');
        echo json_encode($data);exit;
    }
    //帮助中心
    public function help(){
        $user=getuser($this->uid);
        $lists=db('article')->where('catid',1)->select();
        $this->assign('lists', $lists);
        $this->assign('user', $user);
        $this->assign('title','文章列表');
        return $this->fetch();
    }
    //帮助中心-内容
    public function help_content(){
        $user=getuser($this->uid);
        $id=input('id');
        $content=db('article')->where('id',$id)->find();
        $this->assign('user', $user);
        $this->assign('content', $content);
        $this->assign('title','文章详情');
        return $this->fetch();
    }
//理财
    public function licai(){
        $user=getuser($this->uid);
        /*        $data=input('');


                $data=array('state'=>0000,'msg'=>'当前为非交易日');
                echo json_encode($data) ;die();*/
        $this->assign('user', $user);
        $this->assign('title','理财');
        return $this->fetch();
    }
    //理财订单
    public function licai_order(){
        $user=getuser($this->uid);
        $lists=db('licai_order')
            ->where('uid',$user['id'])
            ->order('id desc')
            ->limit('100')
            ->select();
        $this->assign('lists', $lists);
        $this->assign('user', $user);
        $this->assign('title','理财订单');
        return $this->fetch();
    }
    public function licai_order_jia(){
        $data=array(
            'amount'=>"10000.00",
            'coin_id'=>"2",
            'createtime'=>"2018-12-29 16'=>13'=>55",
            'day_num'=>"360",
            'expiretime'=>"2019-12-24 16'=>13'=>55",
            'hashrate'=>"1.00",
            'id'=>"6781",
            'manage_package_id'=>"8",
            'order_id'=>"LC53815460712354641",
            'package_name'=>"360天",
            'run_days'=>8,
            'starttime'=>"2018-12-29 16'=>13'=>55",
            'status'=>"1",
            'updatetime'=>"2019-01-04 00'=>23'=>22",
        );
        $data=array('state'=>0000,'msg'=>'储蓄钱包余额不足','data'=>$data);
        echo json_encode($data);exit;
    }
    //加仓升级
    public function licai_up(){
        $id=input('id');
        $user=getuser($this->uid);
        $this->assign('user', $user);
        $this->assign('id', $id);
        $this->assign('title','加仓升级');
        return $this->fetch();
    }
    public function  licai_up_do(){
        $user=getuser($this->uid);
        $id=input('id');
        $data=input('post.');
        $sys=getsystem();
        $licai=db('licai_order')->where('id',$id)->find();
        if(empty($data['amount'])||$data['amount']<0){
            $dt=array('state'=>0001,'msg'=>'请输入正确的金额');
            echo json_encode($dt);exit;
        }
        if($data['amount']%$sys['licai']!=0){
            $dt=array('state'=>0001,'msg'=>'请输入正确的金额,'.$sys['licai'].'的倍数');
            echo json_encode($dt);exit;
        }
        if($data['amount']>$sys['licai_max']){
            $data=array('state'=>0001,'msg'=>'请输入正确的金额,最大理财金额为'.$sys['licai_max']);
            echo json_encode($data);exit;
        }
        if(md5($data['safepassword'])!=$user['paypwd']){
            $dt=array('state'=>0001,'msg'=>'安全密码不正确');
            echo json_encode($dt);exit;
        }
        if($data['coin_id']==2){
            if($data['amount']>$user['money_jifen']){
                $dt=array('state'=>0001,'msg'=>'储蓄钱包余额不足');
                echo json_encode($dt);exit;
            }
        }else{
            $amount=$data['amount']*(1+$sys['shouxufei']/100+$sys['tixian_xianzhi']/100+$sys['tixian_fei']/100);
            if($amount>$user['money_benjin']){
                $dt=array('state'=>0001,'msg'=>'流通钱包余额不足');
                echo json_encode($dt);exit;
            }
        }
        if($data['coin_id']==2){
            $mey=$user['money_jifen']-$data['amount'];
            $beizhu="会员选择".$licai['qixian']."天理财期限扣除储蓄钱包".$data['amount'];
            mey_log(1,$user['id'],2,11,$data['amount'],$mey,$beizhu);
            $ok=db('users')->where('id',$user['id'])->setDec('money_jifen',$data['amount']);
        }else{
            $fuxiao=$data['amount']*$sys['shouxufei']/100;
            $shouxufei=$data['amount']*$sys['tixian_xianzhi']/100;
            $jijin=$data['amount']*$sys['tixian_fei']/100;
            $mey=$user['money_benjin']-$data['amount']-$fuxiao-$shouxufei-$jijin;//当前余额
            $jian_mey=$data['amount']+$fuxiao+$shouxufei+$jijin;
            $beizhu="会员选择".$licai['qixian']."天理财期限扣除流通钱包".$data['amount']."手续费:".$shouxufei.",基金结算:".$jijin.",积分结算:".$fuxiao;
            mey_log(3,$user['id'],2,12,$jian_mey,$mey,$beizhu);
            $ok=db('users')->where('id',$user['id'])->setField('money_benjin',$mey);
            $beizhu3="基金结算:".$jijin;
            jifen(5,$user['id'],$jijin,15,1,$beizhu3);
            $beizhu2="积分结算".$fuxiao;
            jifen(4,$user['id'],$fuxiao,16,1,$beizhu2);
        }
        if($ok==true){
            $licai_mey=$licai['mey']+$data['amount'];
            $licai_summey=$licai['summey']+$data['amount']*$sys['fengding'];
            $update=array(
                'mey'=>$licai_mey,
                'summey'=>$licai_summey,
            );
            db('users')->where('id',$user['id'])->setField('treeplace',$licai['qixian']);
            gongxiangsuanli($user['rpath'],$data['amount'],$user['mobile'],$user['relevel'],$user['id']);//共享算力
            $is_ok=db('licai_order')->where('id',$licai['id'])->update($update);
            if($is_ok==true){
                $dt=array('state'=>0000,'msg'=>'加仓完成');
                echo json_encode($dt);exit;
            }else{
                $dt=array('state'=>0001,'msg'=>'加仓失败');
                echo json_encode($dt);exit;
            }

        }


    }
    //选择理财
    public function licai_change(){
        $user=getuser($this->uid);
        $this->assign('user', $user);
        $this->assign('title','选择理财');
        return $this->fetch();
    }
    //理财操作
    public function licai_change_do(){
        $user=getuser($this->uid);
        $sys=getsystem();
        $data=input('post.');
        if(md5($data['safepassword'])!=$user['paypwd']){
            $data=array('state'=>0001,'msg'=>'安全密码不正确');
            echo json_encode($data);exit;
        }
        if($data['amount']%$sys['licai']!=0){
            $data=array('state'=>0001,'msg'=>'请输入正确的金额,'.$sys['licai'].'的倍数');
            echo json_encode($data);exit;
        }
        if($data['amount']>$sys['licai_max']){
            $data=array('state'=>0001,'msg'=>'请输入正确的金额,最大理财金额为'.$sys['licai_max']);
            echo json_encode($data);exit;
        }
        if($data['coin_id']==2){
            if($data['amount']>$user['money_jifen']){
                $data=array('state'=>0001,'msg'=>'储蓄钱包余额不足');
                echo json_encode($data);exit;
            }
        }else{
            $amount=$data['amount']*(1+$sys['shouxufei']/100+$sys['tixian_xianzhi']/100+$sys['tixian_fei']/100);
            if($amount>$user['money_benjin']){
                $data=array('state'=>0001,'msg'=>'流通钱包余额不足');
                echo json_encode($data);exit;
            }
        }
        if($data['coin_id']==2){
            $mey=$user['money_jifen']-$data['amount'];
            $beizhu="会员选择".$data['package_id']."天理财期限扣除储蓄钱包".$data['amount'];
            mey_log(1,$user['id'],2,11,$data['amount'],$mey,$beizhu);
            $ok=db('users')->where('id',$user['id'])->setDec('money_jifen',$data['amount']);
        }else{
            $fuxiao=$data['amount']*$sys['shouxufei']/100;
            $shouxufei=$data['amount']*$sys['tixian_xianzhi']/100;
            $jijin=$data['amount']*$sys['tixian_fei']/100;
            $mey=$user['money_benjin']-$data['amount']-$fuxiao-$shouxufei-$jijin;
            $jian_mey=$data['amount']+$fuxiao+$shouxufei+$jijin;
            $beizhu="会员选择".$data['package_id']."天理财期限扣除流通钱包".$data['amount']."手续费:".$shouxufei.",基金结算:".$jijin.",积分结算:".$fuxiao;
            mey_log(3,$user['id'],2,14,$jian_mey,$mey,$beizhu);
            $ok=db('users')->where('id',$user['id'])->setField('money_benjin',$mey);
            $beizhu3="基金结算:".$jijin;
            jifen(5,$user['id'],$jijin,15,1,$beizhu3);
            $beizhu2="积分结算".$fuxiao;
            jifen(4,$user['id'],$fuxiao,16,1,$beizhu2);
        }
        if($ok==true){
            $array=array(
                'nickname'=>$user['mobile'],
                'mey'=>$data['amount'],
                'qixian'=>$data['package_id'],
                'createtime'=>time(),
                'summey'=>$data['amount']*$sys['fengding'],
                'start'=>0,
                'uid'=>$user['id'],
            );
            $is_ok=db('licai_order')->insert($array);
            if($is_ok==true){
                $beizhulic="会员选择".$data['package_id']."天理财期限，增加理财钱包".$data['amount'];
                mey_log(3,$user['id'],1,17,$data['amount'],$mey,$beizhulic);
                db('users')->where('id',$user['id'])->setField('treeplace',$data['package_id']);
                gongxiangsuanli($user['rpath'],$data['amount'],$user['mobile'],$user['relevel'],$user['id']);//共享算力
                $data=array('state'=>0000,'msg'=>'理财成功');
                echo json_encode($data);exit;
            }
        }else{
            $data=array('state'=>0001,'msg'=>'理财失败');
            echo json_encode($data);exit;
        }


    }
    //继续算力
    public function force(){
        $user=getuser($this->uid);
        $this->assign('user', $user);
        $this->assign('title','继续算力');
        return $this->fetch();
    }
    //选择继续算力
    public function force_change(){
        $user=getuser($this->uid);
        $this->assign('user', $user);
        $this->assign('title','继续算力');
        return $this->fetch();
    }
    //继续算力订单
    public function force_order(){
        $user=getuser($this->uid);
        $this->assign('user', $user);
        $this->assign('title','继续算力订单');
        return $this->fetch();
    }
    //算力值
    public function force_value(){
        $user=getuser($this->uid);
        $lists=db('bonus')->where('uid',$user['id'])->order('id desc')->limit(10)->select();
        $this->assign('lists', $lists);
        $this->assign('user', $user);
        $this->assign('title','算力值');
        return $this->fetch();
    }

    //我的钱包
    public function my_wallet(){
        $user=getuser($this->uid);
        $this->assign('user', $user);
        $this->assign('title','我的钱包');
        return $this->fetch();
    }
    //钱包互转
    public function wallet_change(){
        $user=getuser($this->uid);
        $this->assign('user', $user);
        $this->assign('title','转出');
        return $this->fetch();
    }
    //钱包转入操作
    public function wallet_change_do(){
        $user=getuser($this->uid);
        $sys=getsystem();
        $data=input('post.');
        if($sys['zhuan']=="close"){
            $data=array('state'=>0001,'msg'=>'转账功能已关闭');
            echo json_encode($data);exit;
        }
        if(md5($data['safepassword'])!=$user['paypwd']){
            $data=array('state'=>0001,'msg'=>'安全密码不正确');
            echo json_encode($data);exit;
        }
        if($data['coin_id']==2){
            if($data['amount']>$user['money_jifen']){
                $data=array('state'=>0001,'msg'=>'储蓄钱包余额不足');
                echo json_encode($data);exit;
            }
        }else{
            $amount=$data['amount']*(1+$sys['shouxufei']/100+$sys['tixian_xianzhi']/100+$sys['tixian_fei']/100);
            if($amount>$user['money_benjin']){
                $data=array('state'=>0001,'msg'=>'流通钱包余额不足');
                echo json_encode($data);exit;
            }
        }
        if(empty($data['receipt_username'])){
            $data=array('state'=>0001,'msg'=>'请输入转入会员');
            echo json_encode($data);exit;
        }
        $receipt_username=db('users')->where('mobile',$data['receipt_username'])->find();
        if(empty($receipt_username)){
            $data=array('state'=>0001,'msg'=>'转入会员不存在');
            echo json_encode($data);exit;
        }
        if($data['amount']%$sys['beishu']!=0){
            $data=array('state'=>0001,'msg'=>'数额必须是'.$sys['beishu'].'的整数倍');
            echo json_encode($data);exit;
        }
        if($data['coin_id']==2){
            $mey=$user['money_jifen']-$data['amount'];
            $beizhu="会员".$user['mobile']."转入".$data['receipt_username']."到储蓄钱包，数量为:".$data['amount'];
            mey_log(1,$user['id'],2,21,$data['amount'],$mey,$beizhu,$receipt_username['id'],$data['amount']);
            $ok=db('users')->where('id',$user['id'])->setDec('money_jifen',$data['amount']);
        }else{
            $fuxiao=$data['amount']*$sys['shouxufei']/100;
            $shouxufei=$data['amount']*$sys['tixian_xianzhi']/100;
            $jijin=$data['amount']*$sys['tixian_fei']/100;
            $mey=$user['money_benjin']-$data['amount']-$fuxiao-$shouxufei-$jijin;//剩余的钱
            $jian_mey=$data['amount']+$fuxiao+$shouxufei+$jijin;//扣掉的钱
            $beizhu="会员".$user['mobile']."转入".$data['receipt_username']."到流通钱包，数量为：".$data['amount']."手续费:".$shouxufei.",基金结算:".$jijin.",积分结算:".$fuxiao;
            mey_log(3,$user['id'],2,22,$jian_mey,$mey,$beizhu,$receipt_username['id'],$data['amount']);
            $ok=db('users')->where('id',$user['id'])->setField('money_benjin',$mey);
            $beizhu3="基金结算:".$jijin;
            jifen(5,$user['id'],$jijin,15,1,$beizhu3);
            $beizhu2="积分结算".$fuxiao;
            jifen(4,$user['id'],$fuxiao,16,1,$beizhu2);
        }
        /*    if($ok==true){
                if($data['coin_id']==2){
                    $mey=$user['money_jifen']+$data['amount'];
                    $beizhu="会员".$user['mobile']."转入".$data['receipt_username']."到储蓄钱包，数量为:".$data['amount'];
                    mey_log(1,$receipt_username['id'],1,23,$data['amount'],$mey,$beizhu);
                    db('users')->where('id',$user['id'])->setInc('money_jifen',$data['amount']);
                }else{
                    $mey=$user['money_benjin']+$data['amount'];
                    $beizhu="会员".$user['mobile']."转入".$data['receipt_username']."到流通钱包，数量为:".$data['amount'];
                    mey_log(1,$receipt_username['id'],1,24,$data['amount'],$mey,$beizhu);
                    db('users')->where('id',$user['id'])->setInc('money_benjin',$data['amount']);
                }*/
        $data=array('state'=>0000,'msg'=>'操作成功');
        echo json_encode($data);exit;

        /*   }else{
               $data=array('state'=>0001,'msg'=>'转入失败');
               echo json_encode($data);exit;
           }*/
    }
    //储蓄钱包转入
    public function money_transfer(){
        $user=getuser($this->uid);
        $this->assign('user', $user);
        $this->assign('title','储蓄钱包转入');
        return $this->fetch();
    }
    public function money_transfer_do(){
        $user=getuser($this->uid);
        $sys=getsystem();
        $data=input('post.');
        if($sys['zhuan']=="close"){
            $data=array('state'=>0001,'msg'=>'转账功能已关闭');
            echo json_encode($data);exit;
        }
        if(md5($data['safepassword'])!=$user['paypwd']){
            $data=array('state'=>0001,'msg'=>'安全密码不正确');
            echo json_encode($data);exit;
        }
        if($data['coin_id']==5 or $data['coin_if']==6){
            //  if($data['amount']>$user['money_jifen']){
            $data=array('state'=>0001,'msg'=>'储蓄钱包余额不足');
            echo json_encode($data);exit;
            //    }
        }else{
            $amount=$data['amount']*(1+$sys['shouxufei']/100+$sys['tixian_xianzhi']/100+$sys['tixian_fei']/100);
            if($amount>$user['money_benjin']){
                $data=array('state'=>0001,'msg'=>'流通钱包余额不足');
                echo json_encode($data);exit;
            }
        }
        if($data['amount']%$sys['beishu']!=0){
            $data=array('state'=>0001,'msg'=>'数额必须是'.$sys['beishu'].'的整数倍');
            echo json_encode($data);exit;
        }
        if($data['coin_id']==2){
            $mey=$user['money_jifen']-$data['amount'];
            $beizhu="会员".$user['mobile']."转入".$data['receipt_username']."到储蓄钱包，数量为:".$data['amount'];
            mey_log(1,$user['id'],2,21,$data['amount'],$mey,$beizhu);
            $ok=db('users')->where('id',$user['id'])->setDec('money_jifen',$data['amount']);
        }else{
            $fuxiao=$data['amount']*$sys['shouxufei']/100;
            $shouxufei=$data['amount']*$sys['tixian_xianzhi']/100;
            $jijin=$data['amount']*$sys['tixian_fei']/100;
            $mey=$user['money_benjin']-$data['amount']-$fuxiao-$shouxufei-$jijin;//剩余的钱
            $jian_mey=$data['amount']+$fuxiao+$shouxufei+$jijin;//扣掉的钱
            $beizhu="流通钱包转入到储蓄钱包,转入数额".$data['amount']."手续费:".$shouxufei.",基金结算:".$jijin.",积分结算:".$fuxiao;
            mey_log(3,$user['id'],2,22,$jian_mey,$mey,$beizhu);
            $ok=db('users')->where('id',$user['id'])->setField('money_benjin',$mey);
            $beizhu3="基金结算:".$jijin;
            jifen(5,$user['id'],$jijin,15,1,$beizhu3);
            $beizhu2="积分结算".$fuxiao;
            jifen(4,$user['id'],$fuxiao,16,1,$beizhu2);
        }
        if($ok==true){
            $mey=$user['money_jifen']+$data['amount'];
            $beizhu="流通钱包转入到储蓄钱包,转入数额:".$data['amount'];
            mey_log(1,$user['id'],1,23,$data['amount'],$mey,$beizhu);
            db('users')->where('id',$user['id'])->setInc('money_jifen',$data['amount']);

            $data=array('state'=>0000,'msg'=>'转入成功');
            echo json_encode($data);exit;

        }else{
            $data=array('state'=>0001,'msg'=>'转入失败');
            echo json_encode($data);exit;
        }
    }
    //储蓄钱包
    public function transfer(){
        $page =input('page')?input('page'):1;
        $pageSize =input('limit')?input('limit'):config('pageSize');
        $user=getuser($this->uid);
        $lists=db('money_log')
            ->where(array('userid'=>$user['id']))
            ->where('source=11 or source=21 or source=23')
            ->order('id desc')
            ->paginate(array('list_rows'=>$pageSize,'page'=>$page));
        $page = $lists->render();
        $this->assign('page', $page);
        $this->assign('lists', $lists);
        $this->assign('user', $user);
        $this->assign('title','钱包明细');
        return $this->fetch();
    }
    //储蓄钱包列表
    public function get_user_buy(){
        $info = input();
        echo json_encode($this->get_user_order($info));exit;

    }
    //储蓄钱包列表
    public  function get_user_order($data){
        $user=getuser($this->uid);
        $num = $data['num']?$data['num']*12:0;
        $datas=db('money_log')
            ->where(array('userid'=>$user['id']))
            ->where('source=11 or source=21 or source=23')
            ->order('id desc')
            ->limit($num,12)
            ->select();
        foreach ($datas as $key=>$value){
            $datas[$key]['time']=date("Y-m-d H:i:s",$value['time']);
            if($value['num']>0){
                $str="color-success";
            }else{
                $str="color-danger";
            }
            $datas[$key]['color']=$str;
        }

        return $datas;

    }
    //理财钱包
    public function licai_wallet(){
        $user=getuser($this->uid);
        $summey=db('licai_order')->where('uid',$user['id'])->where('summey','gt',0)->sum('mey');
        $lists=db('money_log')
            ->where(array('userid'=>$user['id']))
            ->where('source=17 or source=18')
            ->order('id desc')
            ->select();
        $this->assign('summey', $summey);
        $this->assign('lists', $lists);
        $this->assign('user', $user);
        $this->assign('title','钱包明细');
        return $this->fetch();
    }
    //理财钱包
    public function getlicaiwallet(){
        $info = input();
        echo json_encode($this->get_licai_wallet($info));exit;
    }
    //理财钱包列表
    public  function get_licai_wallet($data){
        $user=getuser($this->uid);
        $num = $data['num']?$data['num']*12:0;
        $datas=db('money_log')
            ->where(array('userid'=>$user['id']))
            ->where('source=17 or source=18')
            ->order('id desc')
            ->limit($num,12)
            ->select();
        foreach ($datas as $key=>$value){
            $datas[$key]['time']=date("Y-m-d H:i:s",$value['time']);
            if($value['num']>0){
                $str="color-success";
            }else{
                $str="color-danger";
            }
            $datas[$key]['color']=$str;
        }

        return $datas;

    }
    //流通钱包
    public function liutong_wallet(){
        $user=getuser($this->uid);
        $lists=db('money_log')
            ->where(array('userid'=>$user['id']))
            ->where('source=10 or source=13 or source=14 or source=22 or source=24 or source=19')
            ->order('id desc')
            ->select();
        foreach ( $lists as$key=>$v){
            if($v['source']==10 ||$v['source']==13||$v['source']==24){
                $lists[$key]['num']=substr($v['num'],1);
            }
        }
        $this->assign('lists', $lists);
        $this->assign('user', $user);
        $this->assign('title','钱包明细');
        return $this->fetch();
    }
    //流通钱包
    public function getliutongwallet(){
        $info = input();
        echo json_encode($this->get_liutong_wallet($info));exit;
    }
    //流通钱包列表
    public  function get_liutong_wallet($data){
        $user=getuser($this->uid);
        $num = $data['num']?$data['num']*12:0;
        $datas=db('money_log')
            ->where(array('userid'=>$user['id']))
            ->where('source=10 or source=13 or source=22 or source=24 or source=25 or source=19')
            ->order('id desc')
            ->limit($num,12)
            ->select();
        foreach ($datas as $key=>$value){
            $datas[$key]['time']=date("Y-m-d H:i:s",$value['time']);
            if($value['source']==10||$value['source']==13||$value['source']==24){
                $datas[$key]['num']=substr($value['num'],1);
                $str="color-success";
            }else{
                $str="color-danger";
            }
            $datas[$key]['color']=$str;
        }

        return $datas;

    }
    //链接算力钱包
    public function force_wallet(){
        $user=getuser($this->uid);
        $lists=db('money_log')
            ->where(array('userid'=>$user['id']))
            ->where('source=13 or source=12')
            ->order('id desc')
            ->select();
        $this->assign('lists', $lists);
        $this->assign('user', $user);
        $this->assign('title','钱包明细');
        return $this->fetch();
    }
    //链接算力钱包
    public function getforce_wallet(){
        $info = input();
        echo json_encode($this->get_force_wallet($info));exit;
    }
    //链接算力钱包列表
    public  function get_force_wallet($data){
        $user=getuser($this->uid);
        $num = $data['num']?$data['num']*12:0;
        $datas=db('money_log')
            ->where(array('userid'=>$user['id']))
            ->where('source=13 or source=12')
            ->order('id desc')
            ->limit($num,12)
            ->select();
        foreach ($datas as $key=>$value){
            $datas[$key]['time']=date("Y-m-d H:i:s",$value['time']);
            if($value['source']==12){
              /*  $datas[$key]['num']=substr($value['num'],1);*/
                $str="color-success";
            }else{
                $str="color-danger";
            }
            $datas[$key]['color']=$str;
        }

        return $datas;

    }

    //节点算力钱包
    public function jiedian_force_wallet(){
        $user=getuser($this->uid);
        $lists=db('money_log')
            ->where(array('userid'=>$user['id']))
            ->where('source=9 or source=10')
            ->order('id desc')
            ->select();
        $this->assign('lists', $lists);
        $this->assign('user', $user);
        $this->assign('title','钱包明细');
        return $this->fetch();
    }

    //节点算力钱包
    public function getjiedian_wallet(){
        $info = input();
        echo json_encode($this->get_jiedian_wallet($info));exit;
    }
    //节点算力钱包列表
    public  function get_jiedian_wallet($data){
        $user=getuser($this->uid);
        $num = $data['num']?$data['num']*12:0;
        $datas=db('money_log')
            ->where(array('userid'=>$user['id']))
            ->where('source=9 or source=10')
            ->order('id desc')
            ->limit($num,12)
            ->select();
        foreach ($datas as $key=>$value){
            $datas[$key]['time']=date("Y-m-d H:i:s",$value['time']);
            if($value['source']==9){
                /*  $datas[$key]['num']=substr($value['num'],1);*/
                $str="color-success";
            }else{
                $str="color-danger";
            }
            $datas[$key]['color']=$str;
        }

        return $datas;

    }
    //消费积分
    public function score(){
        $user=getuser($this->uid);
        $lists=db('money_log')
            ->where(array('userid'=>$user['id']))
            ->where('source',16)
            ->order('id desc')
            ->select();
        $this->assign('lists', $lists);
        $this->assign('user', $user);
        $this->assign('title','钱包明细');
        return $this->fetch();
    }
    //消费积分钱包
    public function getscore(){
        $info = input();
        echo json_encode($this->get_score($info));exit;
    }
    //消费积分钱包列表
    public  function get_score($data){
        $user=getuser($this->uid);
        $num = $data['num']?$data['num']*12:0;
        $datas=db('money_log')
            ->where(array('userid'=>$user['id']))
            ->where('source',16)
            ->order('id desc')
            ->limit($num,12)
            ->select();
        foreach ($datas as $key=>$value){
            $datas[$key]['time']=date("Y-m-d H:i:s",$value['time']);
            if($value['num']>0){
                /*  $datas[$key]['num']=substr($value['num'],1);*/
                $str="color-success";
            }else{
                $str="color-danger";
            }
            $datas[$key]['color']=$str;
        }

        return $datas;

    }
    //基金账户
    public function fund(){
        $user=getuser($this->uid);
        $lists=db('money_log')
            ->where(array('userid'=>$user['id']))
            ->where('source',15)
            ->order('id desc')
            ->select();
        $this->assign('lists', $lists);
        $this->assign('user', $user);
        $this->assign('title','钱包明细');
        return $this->fetch();
    }
    //消费积分钱包
    public function getfund(){
        $info = input();
        echo json_encode($this->get_fund($info));exit;
    }
    //消费积分钱包列表
    public  function get_fund($data){
        $user=getuser($this->uid);
        $num = $data['num']?$data['num']*12:0;
        $datas=db('money_log')
            ->where(array('userid'=>$user['id']))
            ->where('source',15)
            ->order('id desc')
            ->limit($num,12)
            ->select();
        foreach ($datas as $key=>$value){
            $datas[$key]['time']=date("Y-m-d H:i:s",$value['time']);
            if($value['num']>0){
                /*  $datas[$key]['num']=substr($value['num'],1);*/
                $str="color-success";
            }else{
                $str="color-danger";
            }
            $datas[$key]['color']=$str;
        }

        return $datas;

    }
    //邀请好友
    public function invite_friends(){
        $user=getuser($this->uid);
        $url="http://www.xiguvip.com/user/login/regist?invite_code=".$user['mobile'];
        $this->assign('user', $user);
        $this->assign('url', $url);
        $this->assign('title','邀请好友');
        return $this->fetch();
    }
    //生成二维码
    public function erweima(){
        $user=getuser($this->uid);
        $url="http://www.xiguvip.com/user/login/regist?invite_code=".$user['mobile'];
        $img="http://qr.liantu.com/api.php?text=".$url;
        $this->assign('user', $user);
        $this->assign('img', $img);
        $this->assign('title','二维码海报');
        return $this->fetch();
    }
    //社区建设
    public function community_construction(){
        $user=getuser($this->uid);
        $this->assign('user', $user);
        $this->assign('title','社区管理');
        return $this->fetch();
    }
    public function tiaozhuan(){
        $url="http://www.sdmiaoliyuan.com/index.php/wap/";
        return $this->redirect($url);
    }

}